package Controller;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

import Model.Category;
import Model.HibernateUtils;
import Model.Supplier;

public class ControladorProveedor {
	public void insertarProv(String cedula, String nombre, String direccion) {
		Session session = HibernateUtils.SESSION_FACTORY.openSession();
		session.beginTransaction();
		Supplier su = new Supplier();
		su.setCed(cedula);
		su.setDirec(direccion);
		su.setNombre(nombre);
		session.save(su);
		session.getTransaction().commit();
		session.close();
	}

	
	public List<Supplier> cargarTodos() {
		Session session = HibernateUtils.SESSION_FACTORY.openSession();
		List<Supplier> lst = session.createCriteria(Supplier.class).list();
		session.close();// end of session
		return lst;
	}
	public void Eliminar(Supplier su) {
		Session session = HibernateUtils.SESSION_FACTORY.openSession();
		session.beginTransaction();// beginning of the transaction
		session.delete(su);
		session.getTransaction().commit();// end of transaction
		session.close();// end of session

	}

	public void Actualizar(Supplier sup) {
		Session session = HibernateUtils.SESSION_FACTORY.openSession();
		session.beginTransaction();
		session.saveOrUpdate(sup);
		session.getTransaction().commit();
		session.close();
	}


}
